<template>
  <div>
    <section>
      <el-button type="primary" plain @click="()=>triggermodify()" size="mini">mock新增</el-button>
    </section>
    <section style="margin-top: 10px;">
<!--      {{ keyproperlist }}-->
      <ul>
        <li v-for="keyitem in keyproperlist" style="margin-bottom: 10px;">
        <span>{{keyitem&&keyitem.Field}}：</span>
          <input type="text" v-model="rowData[keyitem.Field]"
           v-if="keyitem&&keyitem.Key!='PRI'"
          />
        </li>
      </ul>
    </section>
  </div>
</template>
<script>
import axios from 'axios';
import Mock from 'mockjs'
import lodash from 'lodash';
import { dateFormatYYYYMMDDHHmmss } from '@/utils/date';
export default {
  data() {
    return {
      tableName: '',
      datasourceDto: {},
      keyproperlist: [],
      rowData: {},
    };
  },
  methods: {
    async initByDialog(_data) {
      this.tableName = _data && _data.tableName;
      console.log('-> this.tableName', this.tableName);
      this.datasourceDto = _data && _data.datasourceDto;
      console.log('-> this.datasourceDto', this.datasourceDto);

      var list_res = await axios.post('/api/databaseui/tableproperty', {
        datasourceDto: this.datasourceDto,
        tableName: this.tableName,
      }).then(res => res.data);
      var list = list_res && list_res.data || [];
      this.keyproperlist = list;
      console.log('-> this.keyproperlist', this.keyproperlist);


    },
    async submitByDialog() {
      //validate
      //data operation
      //ajax 提交
      return { success: true,data:lodash.cloneDeep(this.rowData) };
    },

//填充默认的数据
    triggermodify() {
      for (let i = 0; i < this.keyproperlist.length; i++) {
      var keyitem=this.keyproperlist?.[i]
      var key=keyitem?.Field
      var type=keyitem?.Type
      var comment=keyitem?.Comment

        var pri=keyitem?.Key
        if(pri=='PRI'){
          continue
        }
        var _comment=comment;


        if(type.indexOf('int')>=0){
          _comment=1;
        }


        if(key=='tenant_type'){
          _comment=2;
        }
        if(key=='del_state'){
          _comment=1;
        }
        if(key=='tenant_id'){
          _comment=2;
        }


        if(type.indexOf('date')>=0){
          _comment=dateFormatYYYYMMDDHHmmss(new Date());
        }


        this.rowData[key]=_comment

      }


      this.$forceUpdate()
    },
  },
};
</script>
